package com.example.myapplication.net.usecase;

import com.example.myapplication.bean.LoginDetailBean;
import com.example.myapplication.net.repository.IMainRepository;
import com.example.myapplication.net.repository.MainRepository;
import com.example.common.base.INetCallBack;
import com.example.common.base.UseCase;
import ohos.app.Context;

/**
 * @author geyao
 * @date 2021/7/6
 * des:
 */
public class LoginUseCase extends UseCase<LoginDetailBean> {
    private final String phoneNum;
    private final String verifyCode;
    private final IMainRepository repository;

    public LoginUseCase(Context context, boolean isShowLoading, String phoneNum, String verifyCode) {
        super(context, isShowLoading);
        this.phoneNum = phoneNum;
        this.verifyCode = verifyCode;
        this.repository = new MainRepository(context);
    }

    @Override
    public void buildWork(INetCallBack<LoginDetailBean> callBack) {
        try {
            LoginDetailBean login = repository.login(phoneNum, verifyCode);
            callBack.onNext(login);
        } catch (Exception e) {
            e.printStackTrace();
            callBack.onError(e);
        }
    }
}
